<?php
declare (strict_types=1);

namespace app\admin\controller\V1;

use app\admin\controller\BaseModule;
use app\common\logic\AdminUserLogic;
use think\facade\Request;
use tinywan\JWT;

/**=========================================
 * Copyright © 2023-2024, WICMS.CN. All Rights Reserved
 * Project Name: WiCMS
 * Description: 后台控制器控制器
 * Author: jason
 * Email: 52527998@QQ.COM
 * Date: 2024/9/11
 * Time: 下午4:33
 * File: app\admin\controller\v1\Index.php
 * =========================================
 */
class Index extends BaseModule
{

    public function initialize(): void
    {
        parent::initialize();
    }

    public function index(): void
    {
        $users  = AdminUserLogic::getAdminUserList();
        $user  = $users[0];
        $token = JWT::generateToken($user);
        $this->returnApi('success', $token);
    }

    public function login():void
    {
        $username = input('post.username/s','','trim');
        $password = input('post.password/s','','trim');
        $captcha = input('post.captcha/s','','trim');
        $result = AdminUserLogic::adminUserLogin($username, $password, $captcha);
        if ($result !== true){
            $this->returnApi($result, '', 404);
        }
        $this->returnApi('success',$result);
    }


}